

#include <lapic.h>
#include <cpuid.h>
#include <types.h>
#include <msr.h>

/**
 * Check if the Local APIC exists using CPUID
 * 
 * returns - exists?
 */
bool check_for_apic(void)
{
	dword a, d;
	cpuid(0x01, &a, &d);
	return (d & CPUID_FLAG_APIC);
}

/**
 * Get the base address of the Local APIC
 * 
 * returns - base address of Local APIC
 */
dword get_apic_base(void)
{
	dword a, d;
	msr_read(IA32_APIC_BASE_MSR, &a, &d);
	return (a & 0xFFFFF000);
}

/**
 * Gets if the Local APIC is enabled or not
 * 
 * returns - enabled?
 */
bool get_apic_enabled(void)
{
	dword a, d;
	msr_read(IA32_APIC_BASE_MSR, &a, &d);
	return ((a & (1 << 11)) >> 11);
}
